package com.activiti6.demo.restfultask;

import com.activiti6.demo.restfultask.httpclient.HttpClient;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.Expression;
import org.activiti.engine.delegate.JavaDelegate;

public class RestfulDelegate implements JavaDelegate {
    /*
     *  这些变量我们都在流程中进行了定义，
     * 也就是说通过流程注入到了这个代理类中，当然要用activiti流程注入，
     * 就要使用activiti的数据类型Expression
     * */
    private Expression rest;
    private Expression json;

    // 要注入当然要有set方法
    public void setRest(Expression rest) {
        this.rest = rest;
    }

    public void setJson(Expression json) {
        this.json = json;
    }

    @Override
    public void execute(DelegateExecution execution) { // throws Exception {
        String url = (String) rest.getValue(execution);
        String jsonString = (String)json.getValue(execution);

//        String result = HttpClientUtil.doPost(url, jsonString, "utf-8");
        String result = HttpClient.doPost(url, jsonString, "utf-8");

        System.out.println("↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓");
        System.out.println();
        System.out.println();
        System.out.println(jsonString + "目前的工作地点是—————————————————————————>" + result);
        System.out.println();
        System.out.println();
        System.out.println("↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑");
    }

}
